<!DOCTYPE html>
<html>
    <body>
        <button onclick="createcat()">创建动物示例</button>
        <button onclick="createobject1()">使用组合继承</button>

        <script type="text/javascript">
            function Animal(name){
                this.name = name;
                this.sayName = function() {
                    window.alert(this.name);
                };
            }
            function Cat(name,age){
                // 使用父类的构造函数
                Animal.call(this,name)
                this.age = age
            }
            // 创建一只猫
            createcat = function(){
                let cat = new Cat('Ketty',16);
                cat.sayName();

                let dog = new Dog('dog',23);
                dog.sayName();
            }

            function Dog(name,age){
                // 使用了对象冒充
                this.animal = Animal
                this.animal(name)
            }


          
            function Car(name){
                this.name = name
            }
            Car.prototype = {
                sayName:function(){
                    window.alert(this.name+'----'+this.sno)
                }
            }
            function Hongqi(name,sno){
                // 继承属性
                Car.call(this,name)
                this.sno = sno
            }
            // 继承方法
            Hongqi.prototype = new Car();
            createobject1 = function () {
                let hongqi = new Hongqi('hongqi',1001);
                hongqi.sayName();
            }

        </script>
    </body>
</html>